<?php
class Web_Plugin_SessionCheck extends Zend_Controller_Plugin_Abstract
{
	private $_pages = array(
		'cliente' => array( 
			'my-data' => true,
			'my-orders' => true,
			'pedido' => true,
			'link-address' => true,
			'my-addresses' => true,
			'eliminar-direccion' => true,
			'votar' => true,
		)
	);
	
	
    public function preDispatch (Zend_Controller_Request_Abstract $request)
    {
        $bootstrap = Zend_Controller_Front::getInstance()->getParam('bootstrap');
        $options = $bootstrap->getOptions();
        $controller = $this->getRequest()->getControllerName();
        $action = $this->getRequest()->getActionName();
        
        if ( isset( $this->_pages[$controller][$action]) ) {
            if ($options['auth']['active']) {
                $this->checkSession();
            }
        }
    }
    /**
     * checkSession
     */
    public function checkSession ()
    {
        $session = Zend_Registry::get('session');
        if (!isset( $session->idCliente )) {
            $session->loginTrigger = true;
            $session->comeBack = $this->getRequest()->getRequestUri();
            $this->getResponse()->setRedirect('/')->sendResponse();
            exit;
        }
    }
}
